local meta = FindMetaTable( "Player" )

function meta:AddItem(item)
	for k,v in pairs(Basewars.Items) do
		if v.Class == item then
			if v.Stackable && self:HasItem(item) then
				for inv,ite in pairs(self.Inventory) do
					if ite.Class == item then
						ite.Stack = ite.Stack + 1
					end
				end
			else
				table.insert(self.Inventory,v)
			end
			umsg.Start("AddItem",self)
				umsg.Char(v.ID)
			umsg.End()
			break
		end
	end
end

function meta:RemoveItem(item)
	if self:HasItem(item) then
		for k,v in pairs(Basewars.Items) do
			if v.Class == item then
				for inv,ite in pairs(self.Inventory) do
					if ite.Class == item then
						if ite.Stack && ite.Stack > 1 then
							ite.Stack = ite.Stack - 1
							Msg("Removing Stack")
						else
							table.remove(self.Inventory,inv)
							Msg("Removing Item")
						end
					end
				end
				umsg.Start("RemoveItem",self)
					umsg.Char(v.ID)
				umsg.End()
				break
			end
		end
	end
end

function meta:DropItem(item)
	if self:HasItem(item) then
		local item = FindItem(item)
		if item then
			local drop = item:Drop(self) 
			if drop then
				local ent = ents.Create(drop) 
				ent.Model = v.Model
				ent.Class = v.Class
				local vStart = self:GetShootPos();
				local vForward = self:GetAimVector();
				local trace = {};
				trace.start = vStart;
				trace.endpos = vStart + (vForward * 100);
				trace.filter = self;
				local tr = util.TraceLine( trace );
				ent:SetPos(tr.HitPos + Vector(0, 0, 32))
				self:RemoveItem(Obj)
				ent:Spawn()								
			end
		end
	end	
end

function meta:HasItem(item)
	for k,v in pairs(self.Inventory) do
		if v.Class == item then
			return true
		end
	end
	return false		
end

function FindItem(item)
	for k,v in pairs(Basewars.Items) do
		if v.Class == item then
			return v
		else
			return false
		end
	end
end

function GM:ShowTeam(ply)
umsg.Start("ShowInv",ply)
umsg.End()
end





